﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Excel2DbTool.Helpers
{
    //对于那些可能多次用到的值其实应该缓存起来
    public static class ConfigHelper
    {
        public static String DbType
        {
            get
            {
#if DEBUG
                string dbType = "ORACLE";
#else
                 string dbType = GetAppSettingValueByKey("DbType");
#endif

                return dbType;
            }
        }

        public static String TableName
        {
            get
            {
                return "KANQ_TT"; //TemTableForMigraterData_CANGQ
                //string tableName = GetAppSettingValueByKey("TableName");
                //return tableName;
            }
        }

        public static String DbConnectStr
        {
            get
            {
#if DEBUG
                //string dbConnectStr = "Host=192.168.1.105;Port=1521;User ID=BDCDJKR;Password=BDCDJKR;SID=orcl";
                string dbConnectStr = "Host=127.0.0.1;Port=1523;User ID=admin;Password=admin;SID=orcl";
#else
                 string dbConnectStr = GetAppSettingValueByKey("DbConnectStr");
#endif

                return dbConnectStr;

            }
        }

        private static Dictionary<string, string> cache = new Dictionary<string, string>(10);
        static string GetAppSettingValueByKey(string key)
        {
            if (!cache.ContainsKey(key))
            {
                string val = System.Configuration.ConfigurationManager.AppSettings[key];
                cache.Add(key, val);
            }
            return cache[key];
        }
    }
}
